package com.lab.image.process;

import android.app.Activity;
import android.graphics.Bitmap;
import android.view.View;

/**
 * Created by ak
 */
public class MakeImageUtil {

    public static Bitmap takeScreenShot(Activity activity) {
        View view = activity.getWindow().getDecorView();
        view.setDrawingCacheEnabled(true);
        view.buildDrawingCache();
        Bitmap b1 = view.getDrawingCache();
        Bitmap result = resizeBitmap(b1);
        view.destroyDrawingCache();
        BlurProcessor processor = new BlurProcessor();
        result = processor.blur(result, 8f);
        return result;
    }

    private static Bitmap resizeBitmap(Bitmap bitmap) {
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        int resizeWidth = width;
        int resizeHeight = height;
        //按大的边等比例缩小
        if (width > height) {
            if (width > 100) {
                resizeWidth = 100;
                resizeHeight = height * 100 / width;
            }
        } else {
            if (height > 100) {
                resizeWidth = width * 100 / height;
                resizeHeight = 100;
            }
        }

        return Bitmap.createScaledBitmap(bitmap,
                resizeWidth, resizeHeight, true);
    }
}